<!DOCTYPE html>
<html lang="en">
  <head>
    <meta charset="UTF-8" />
    <meta name="viewport" content="width=device-width, initial-scale=1.0" />
    <title>Document</title>
  </head>
  <body>
    <script>
      function askPassword(ok, fail) {
        let password = prompt("Password?", "");
        if (password == "123123") ok();
        else fail();
      }
      let user = {
        name: "John",
        login(result) {
          console.log(
            this.name + (result ? " logged in" : " failed to log in")
          );
        },
      };
      askPassword(user.login.bind(user, true), user.login.bind(user, false));
    </script>
  </body>
</html>
